'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.getFixLack = exports.getUpdaterKeys = exports.genUpdater = undefined;

var _defineProperty2 = require('babel-runtime/helpers/defineProperty');

var _defineProperty3 = _interopRequireDefault(_defineProperty2);

var _toArray2 = require('babel-runtime/helpers/toArray');

var _toArray3 = _interopRequireDefault(_toArray2);

var _set = require('lodash/set');

var _set2 = _interopRequireDefault(_set);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var regOperation = /\.\$(set|merge|apply|push|unshift|splice)$/;
var genUpdater = exports.genUpdater = function genUpdater(updater) {
    var rst = {};
    for (var key in updater) {
        var path = regOperation.test(key) ? key : key + '.$set';
        (0, _set2.default)(rst, path, updater[key]);
    }
    return rst;
};
var getUpdaterKeys = exports.getUpdaterKeys = function getUpdaterKeys(updater) {
    var rst = [];
    for (var key in updater) {
        rst.push(key.replace(regOperation, ''));
    }
    return rst;
};
var getFixLack = exports.getFixLack = function getFixLack() {
    var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';

    if (!path) {
        return {};
    }

    var _path$split = path.split('.'),
        _path$split2 = (0, _toArray3.default)(_path$split),
        first = _path$split2[0],
        tail = _path$split2.slice(1);

    var lack = (0, _set2.default)({}, tail, {});
    return (0, _defineProperty3.default)({}, first, {
        $set: lack
    });
};
exports.default = genUpdater;